package com.example.gkcircle.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avos.avoscloud.AVUser;
import com.example.gkcircle.R;
import com.example.gkcircle.activity.PhotoViewAcitivty;
import com.example.gkcircle.bean.Lost;
import com.example.gkcircle.fragment.lost.search.SearchLostFragment;
import com.example.gkcircle.library.object.DetailBook;
import com.example.gkcircle.utils.UniversalImageLoader;
import com.ms.square.android.expandabletextview.ExpandableTextView;

import java.util.List;

import me.next.tagview.TagCloudView;

/**
 * 失物搜索
 * Created by Jehu on 16/3/19.
 */
public class BookDetailAdapter extends BaseAdapter{


    private DetailBook mData;
    private String[] mTitle;
    private Activity mActivity;
    private final int MAX=3;
    private LayoutInflater inflater;

    public BookDetailAdapter(Activity mActivity, DetailBook data) {
        this.mData=data;
        this.mActivity = mActivity;
        this.mTitle=mActivity.getResources().getStringArray(R.array.detail_title);
        this.inflater = LayoutInflater.from(mActivity);
    }

    @Override
    public int getCount() {
        return mData==null?0:MAX;
    }

    @Override
    public Object getItem(int position) {
        return mData;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    static class ViewHolder{
        TextView title;
        ExpandableTextView expandableTextView;
        TagCloudView tagCloudView;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView=inflater.inflate(R.layout.library_book_detail_item,null);
            viewHolder.title=(TextView)convertView.findViewById(R.id.library_book_detail_item_title);
            viewHolder.expandableTextView=(ExpandableTextView)convertView.findViewById(R.id.library_book_detail_item_expanable_tv);
            viewHolder.tagCloudView=(TagCloudView)convertView.findViewById(R.id.library_book_detail_item_tag);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder)convertView.getTag();
        }
        DetailBook detailBook=mData;

        viewHolder.title.setText(mTitle[position]);

        switch (position){
            case 0:
                viewHolder.expandableTextView.setVisibility(View.VISIBLE);
                viewHolder.tagCloudView.setVisibility(View.GONE);
                viewHolder.expandableTextView.setText(detailBook.getIntro());
                break;
            case 1:
                viewHolder.expandableTextView.setVisibility(View.VISIBLE);
                viewHolder.tagCloudView.setVisibility(View.GONE);
                viewHolder.expandableTextView.setText(detailBook.getCatalog());
                break;
            case 2:
                viewHolder.expandableTextView.setVisibility(View.GONE);
                viewHolder.tagCloudView.setVisibility(View.VISIBLE);
                viewHolder.tagCloudView.setTags(detailBook.getTag());
                break;
        }
        return convertView;
    }
}
